<?php
session_start();
include_once("check_login.php");
include_once("class/common.fun.php");
include_once("class/MySqlConnect.class.php");

$auction_id = $_GET['auction_id'] ;
if (empty($auction_id)) {
	showMessage("Operation of an error");
}
if (!is_numeric($auction_id)) {
	showMessage("Operation of an error");
}

if (isset($_POST['active'])) {
	$active = $_POST['active'];
	if ($active == "add_price") {
		$price = trim($_POST['price']);
		$maxprice = maxPrice($auction_id);
		if (empty($price)) {
			showMessage("Please enter your price");
		}
		if (!is_numeric($price)) {
			showMessage("Price can only be number");
		}
		
		if ($maxprice>$price) {
			showMessage("The price is less than the current highest bid");
		}
		
		$_MySqlConnect = new MySqlConnect();
		$_MySqlConnect->insert("bid_price", array("user_id"=>$_SESSION['user_id'],"auction_id"=>$auction_id,"price"=>$price,"add_time"=>date("Y-m-d H-i-s")));
		$_MySqlConnect = null;
		showMessage("Successfully added","GoUrl","list.php");
	}
}

$_MySqlConnect = new MySqlConnect();
$sql = "SELECT * FROM auction where auction_id = ".$auction_id." LIMIT 0,1";
$arr_list = $_MySqlConnect->execute($sql);
if (empty($arr_list)) {
	showMessage("Operation of an error");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Add the price </title>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="">
<input name="active" type="hidden" value="add_price">
<input name="auction_id" type="hidden" value="<?php echo $auction_id;?>">
  <tr>
    <td width="156" height="30"><div align="right"><SPAN id="result_box"><SPAN closure_hashCode_4om4wx="18">Item   Code</SPAN></SPAN>:</div></td>
    <td width="444"><?php echo $arr_list[0]['auction_code'];?></td>
  </tr>
  
  <tr>
    <td height="30"><div align="right">Lowest   price:</div></td>
    <td><?php echo $arr_list[0]['lowest_price'];?></td>
  </tr>
  <tr>
    <td height="30"><div align="right">Auction cut-off   time:</div></td>
    <td><?php echo $arr_list[0]['at_term'];?></td>
  </tr>
  <tr>
    <td height="30"><div align="right">Project   Description:</div></td>
    <td><?php echo $arr_list[0]['auction_content'];?></td>
  </tr>
  <tr>
    <td height="30"><div align="right"><SPAN id="result_box"><SPAN closure_hashCode_4om4wx="46">Has   offered</SPAN></SPAN>:</div></td>
    <td height="30">
	<?php
	$price = maxPrice($arr_list[0]['auction_id']);
	if($price>0){
		echo $price;
	}else{
		echo "No bids";
	}
	?>	</td>
  </tr>
  <tr>
    <td height="30"><div align="right"><SPAN id="result_box"><SPAN closure_hashCode_4om4wx="56">My   bids</SPAN></SPAN>:
    </div>      <label></label></td>
    <td height="30"><input name="price" type="text" id="price" size="30"></td>
  </tr>
  <tr>
    <td height="30" colspan="2">
	<div align="center">
      <label>
        <input type="submit" name="Submit" value="Submit">
&nbsp;&nbsp;&nbsp; </label>
      <label>
      <input type="reset" name="Submit2" value="Reset">
      </label>
      </div>     </td>
  </tr>
  </form>
</table>
</body>
</html>
